<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>文件传阅详情-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart id="xs_c" style="background: #fff;">
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left"><a onclick="back()" href="javascript:;" class="icon icon-109 f-white">返回</a></div>
	    	<h1 class="weui-header-title">文件传阅详情</h1>
		</div>
		<div class="weui_tab_bd pb0">
			<div class="weui-weixin">
				<div class="weui-weixin-ui">
				   <div class="weui-weixin-page border-bottom1">
					   <div class="weui-weixin-info pt10 mb0">
	                     <span class="weui-weixin-em">发布人：</span>
	                      <em class="weui-weixin-em" >${notice.sender } 老师</em>
	                    </div>
				   </div>
				   <div class="weui-weixin-page border-bottom1">
					   <div class="weui-weixin-info pt10 mb0">
	                     <span class="weui-weixin-em">发布时间：</span>
	                      <em class="weui-weixin-em" ><fmt:formatDate value="${notice.createTime}" type="time" timeStyle="short"/></em>
	                    </div>
					</div>
					<c:if test="${notice.guideContent != null && !empty notice.guideContent}">
						<div class="weui-weixin-page">
						   <div class="weui-weixin-info pt10 mb0">
		                     <span class="weui-weixin-em f-green">校长批示：</span>
		                      <em class="weui-weixin-em f-red" >
		                      	${notice.guideContent }
		                      </em>
		                    </div>
						</div>
					</c:if>
				  </div>
				</div>
				<div class="weui_cells xs_c_content mt0">
				    <div class="weui-weixin-content">
	                    <p id="noticeContent">${notice.content }</p>
	                </div>
				</div>
				<input type="hidden" id="noticeId" value="${notice.id }"/>
				<input type="hidden" id="shareName" value="${user.teacher.name }"/>
				<div class="weui_cells xs_c_piclist">
	                <div class="xs_c_picWrap clearfix img-click">
	                	<c:forEach var="item" items="${notice.attachList }">
	                		<c:if test="${item.attachmentType == 'image' }">
	                			<div class="xs_c_pic"><img onclick="imgClick(this)" src="${config.imgUrl }${item.attachmentUrl}"></div>
	                		</c:if>
	                	</c:forEach>
	                </div>
				</div>
				
				<div class="weui_cells xs_c_piclist p5">
	                <div class="xs_c_picWrap clearfix">
						<c:forEach var="item" items="${notice.attachList }">
							<c:if test="${item.attachmentType != 'image' }">
								<div class="xtbg-upload-list mb10">
									<div class="xtbg-upload-list-inner">
										<p>${item.attachmentName}</p>
										<a href="${config.imgUrl}${item.attachmentUrl}" class="weui_btn weui_btn_mini weui_btn_primary f-white bg-blue">查看</a>
									</div> 
								</div>
							</c:if>
						</c:forEach>
					</div>
				</div>
				<div class="page-bd mb120">
					<ul>
						<li class="xs_c_search-first js-show" style="margin:0;">
			                <div class="weui-flex js-category">
			                    <p class="weui-flex-item"><img class="middle" src="<%=basePath%>/images/weichakan.png"/> 接收人列表</p>
			                </div>
			                <div class="page-category js-categoryInner">
			                    <ul class="list_5" id="sendeeList">
			                    </ul>
			                </div>
			            </li>
					</ul>
				</div>
				<c:if test="${!isPrincipal }">
					<div class="weui_cells afterNone" style="position: fixed;bottom: 0;width: 100%;">
						<c:choose>
							<c:when test="${notice.isRead == 1}">
								<p style="padding: 15px 0;text-align: center;"><i class="weui_icon_success"></i>
								<span class="f-green">  已阅</span>
								</p>
							</c:when>
							<c:otherwise>
								<div class="weui_btn_area">
							        <a href="javascript:" id="readSubmit" class="weui_btn bg-green">已阅</a>
							    </div>
							</c:otherwise>
						</c:choose>
					</div>
				</c:if>
				<!--查看状态-->
				<%-- <div class="page-bd xs_c_search">
					<ul>
						<li class="xs_c_search-first">
			                <div class="weui-flex js-category">
			                    <p class="weui-flex-item"><img class="middle" src="<%=basePath%>/images/weichakan.png"/> 未查看（<span id="noReadCount"></span>）</p>
			                    <button class="weui_btn bg-blue weui_btn_mini" style="display:none;margin-right: 20px;" id="resetSend"> 重发 </button> 
			                    <i class="icon icon-74"></i>
			                </div>
			                <div class="page-category js-categoryInner">
			                    <ul class="list_5" id="noRead">
			                    </ul>
			                </div>
			            </li>
			            <li class="">
			                <div class="weui-flex js-category">
			                    <p class="weui-flex-item"><img class="middle" src="<%=basePath%>/images/yichakan.png"/> 已查看（<span id="readedCount"></span>）</p>
			                    <i class="icon icon-74"></i>
			                </div>
			                <div class="page-category js-categoryInner">
			                    <ul class="list_5" id="readed">
			                    </ul>
			                </div>
			            </li>
					</ul>
				</div> --%>
				<!--End查看状态-->
			<c:if test="${isPrincipal && notice.guideStatus == '001'}">
				<div class="weui_cells mt0 mb45">
					<div class="weui_cell">
						<div class="weui_cell_bd weui_cell_primary">
							<p>校长批示</p>
						</div>
					</div>
					<div class="weui_cell">
		                <div class="weui_cell_bd weui_cell_primary">
		                    <textarea id="guideContent" class="weui_textarea" placeholder="请输入批示内容……" rows="5"></textarea>
		                </div>
		            </div>
				</div>
				<script id="teacher-table-template" type="text/x-handlebars-template">	
	 				<div class="js-categoryInner">
		               <div class="weui_cells afterNone" style="margin: 0;">
							<ul class="list_3">
								{{#each list}}
					            <li>
									<div class="weui_cell_hd list_c3" style="display: inline-flex;padding-left: 10px;">
										<label class="weui_cells_checkbox weui_check_label" style="padding-right: 15px;" for="{{id}}">
											<input type="checkbox" class="weui_check" checked value="{{id}}" id="{{id}}">
				        					<i class="weui_icon_checked"></i>
										</label>{{name}}	
									</div>
								</li>
								{{/each}}
					        </ul>
						</div>
		            </div>
				</script>
				<div class="weui_cells mt0 mb55"></div>
				<section class="weui-menu f-white">
			        <div class="weui-menu-inner bg-green f-16" id="sendSubmit">
			            <span>提交批示</span>
			        </div>
			    </section>
			</c:if>
		</div>
	</div>
	
</body>
<script type="text/javascript">
	var teacherData = {};
	var sendeeId = parseInt("${sendeeId}");
	var noticeId = parseInt("${notice.id}");
	var senderId = parseInt("${notice.senderId}");
	var isPrincipal = "${isPrincipal}" == 'true' ? true : false;
	var isRead = parseInt("${notice.isRead}");
	var guideStatus = "${notice.guideStatus}";
	var guideId = parseInt("${notice.guideId}");
	$(function() {
		$('.js-category').click(function(){
			$parent = $(this).parent('li');
		    if($parent.hasClass('js-show')){
                $parent.removeClass('js-show');
                $(this).children('i').removeClass('icon-35').addClass('icon-74');
            }else{
                $parent.siblings().removeClass('js-show');
                $parent.addClass('js-show');
                $(this).children('i').removeClass('icon-74').addClass('icon-35');
                $parent.siblings().find('i').removeClass('icon-35').addClass('icon-74');
            }
	   });
	   $("#sendSubmit").click(function() {
		   $.confirm("", "确认提交批示?", function() {
		   	sendSubmit();
		   }, function() {
	       });
	   })
	   $("#readSubmit").click(function() {
		   readUpdate();
	   })
	   if(isRead == 0 && isPrincipal) readUpdate();
	   sendeeList();
	    //老师组织架构返回
		$("#teacherBack").click(function() {
			$("#ls_div_box").hide();
			loadTeacherHtml(teacherData);
		});
     	$("#teacherSure").click(function() {
			$("#ls_div_box").hide();
     	})
	})
	function loadTeacher() {
		$.ajax({
	 		url : basePath + "/teacherOrganizeGroup/10",
	 		type : "post",
	 		dataType : "json",
	 		async : false,
	 		success : function(data) {
	 			if(data != null && data.length > 0) {
	 				var result = [];
	 				for(var i in data) {
	 					if(data[i].id != sendeeId) {
	 						result.push(data[i]);
	 					}
	 				}
	 				teacherData.list = result;
	 				loadTeacherHtml(teacherData);
	 			}
	 		}, error:function(){
	 			alert("查询异常");
      			}
	 	});
	}
	function loadTeacherHtml(teacherData) {
		var myTemplate = Handlebars.compile($("#teacher-table-template").html());
			Handlebars.registerHelper("equal", function(v1,v2,options) {
    		if(v1 == v2) {
    			//满足添加继续执行
    			return options.fn(this);
    		}else {
    			//不满足条件执行{{else}}部分
    			return options.inverse(this);
    		}
    	});
		$('#teacherList').html(myTemplate(teacherData));
	}
	function repeatNotice() {
		$.ajax({
          	url : basePath + "/ls/notice/repeat",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : {
  	 			noticeId: noticeId
  	 		},
            success: function(data){
            	if(data.code == '000') $.toast("操作成功");
            	else $.toast(data.msg, "cancel");
            },
            error: function(xhr, type){
                  
            }
          });
	}
	function readUpdate() {
		var noticeIds = new Array();
		noticeIds.push(noticeId);
		$.ajax({
          	url : basePath + "/notice/read/modify",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : {
  	 			sendeeId: sendeeId,
  	 			noticeIds: noticeIds
  	 		},
            success: function(data){
            	if(data.code == '000') {
            		$(".weui_btn_area").removeClass("weui_btn_area").html('<p style="padding: 15px 0;text-align:center;"><i class="weui_icon_success"></i><span class="f-green">  已阅</span></p>');
            	}
            },
            error: function(xhr, type){
                  
            }
          });
	}
	function sendSubmit() {
		var guideContent = $("#guideContent").val();
		if(guideContent.trim().length == 0) {
			$.toast("请输入批示内容", "forbidden");
			return;
		}
		$.ajax({
          	url : basePath + "/ls/notice/fileAround/send",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : {
  	 			guideContent: guideContent,
  	 			noticeId: noticeId
  	 		},
            success: function(data){
            	if(data.code == '000') {
            		$.toast("操作成功");
            		setTimeout(function(){window.location.reload();}, 1000);
            	}else {
            		$.toast(data.msg, "cancel");
            	}
            },
            error: function(xhr, type){
            }
          });
	}
	function noSendSubmit() {
		var guideContent = $("#guideContent").val();
		$.ajax({
          	url : basePath + "/ls/notice/fileAround/end",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : {
  	 			guideContent: guideContent,
  	 			noticeId: noticeId
  	 		},
            success: function(data){
            	if(data.code == '000') {
            		$.toast("操作成功");
            		setTimeout(window.location.reload(), 1000);
            	}else {
            		$.toast(data.msg, "cancel");
            	}
            },
            error: function(xhr, type){
                  
            }
          });
	}
	function sendeeList() {
		var sendeeType = parseInt("${notice.sendeeType}");
		$.ajax({
          	url : basePath + "/notice/read/list",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : {
  	 			noticeId: noticeId,
  	 			sendeeType: sendeeType
  	 		},
            success: function(data){
            	if(data != null && data.length > 0) {
            		var sendeeListHtml = '';
            		for(var i in data) {
            			var itm = data[i];
            			if(itm.sendeeId != guideId) {
            				var rh = '';
            				if(itm.isRead == 1) {
            					rh = "<span class='pn-a weui-badge'>阅</span>";
            				}
            				sendeeListHtml += "<li class='pn-r' data-id='"+itm.id+"'>" + itm.sendee + rh + "</li>";
            			}
            		}
            		$("#sendeeList").html(sendeeListHtml);
            	}
            },
            error: function(xhr, type){
                  
            }
          });
	}
	function readList() {
		var sendeeType = parseInt("${notice.sendeeType}");
		$.ajax({
          	url : basePath + "/notice/read/list",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : {
  	 			noticeId: noticeId,
  	 			sendeeType: sendeeType
  	 		},
            success: function(data){
            	if(data != null && data.length > 0) {
            		var noReadHtml="", noReadCount=0, readedHtml="", readedCount=0;
            		for(var i in data) {
            			var itm = data[i];
            			var str = "<li>" + itm.sendee + (sendeeType == 1 ? "家长" : "") + "</li>";
            			if(itm.sendeeId != sendeeId) {
            				if(itm.isRead > 0) {
                				readedCount++;
                				readedHtml += str;
                			}else {
                				noReadCount++;
                				noReadHtml += str;
                			}
            			}
            		}
            		$("#noRead").html(noReadHtml);
            		if(noReadCount > 0) $("#resetSend").show();
            		$("#noReadCount").html(noReadCount);
            		$("#readed").html(readedHtml);
            		$("#readedCount").html(readedCount);
            	}
            },
            error: function(xhr, type){
                  
            }
          });
	}
	
</script>
</html>